package com.swpu.project.controller;

import jdk.internal.instrumentation.Logger;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Arrays;
import java.util.function.Consumer;

@RestController

public class TestController {


    @RequestMapping("/test/cookie")
    public String cookie(HttpServletRequest request,
                         HttpServletResponse response,
                         HttpSession session) {

        Cookie[] cookies = request.getCookies();
        if (cookies != null) {

            Arrays.stream(cookies).forEach(new Consumer<Cookie>() {
                @Override
                public void accept(Cookie cookie) {
                    System.out.println(cookie.getName() + " : " + cookie.getValue());
                }
            });

        }
         session.setAttribute("a","ADADD");
        return "index";


    }
    @RequestMapping("/test/s")
    String s(HttpSession session)
    {
        System.out.println(session.getAttribute("a"));
        return "successful";

    }




}



